package com.xf.day04

import org.apache.spark.{SparkConf, SparkContext}

object Test02 {
  def main(args: Array[String]): Unit = {

    // 创建 SparkConf 对象
    val conf = new SparkConf()
      .setAppName("WordCount")
      .setMaster("local[*]")
      .set("spark.ui.port", "8080")
      .set("spark.driver.host", "127.0.0.1")

    // 创建 SparkContext 对象
    val sc = new SparkContext(conf)

    val goods = sc.parallelize(List("radio 30 50", "soap 3 60", "cup 6 50", "bowl 4 80"))

    val goodsTup = goods.map(x => {
      val splits = x.split(" "); (splits(0), splits(1).toInt, splits(2).toInt)
    })

    // 按照商品名称进行排序
   // goodsTup.sortBy(_._1).collect().foreach(println)

    // 按照商品单价降序排序
    goodsTup.sortBy( x => x._2, false).collect().foreach(println)


    // 暂停 10 秒，方便查看 UI
    Thread.sleep(10000000)
    sc.stop()
  }

}
